﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Windows.Forms
{
    /// <summary>
    /// 
    /// </summary>
    [FormCaption(false)]
    public partial class FrmPrompt : FrmBase
    {
        /// <summary>
        /// 
        /// </summary>
        public FrmPrompt()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 文本框内容
        /// </summary>
        public string InputText
        {
            get { return inputTextBox.Text.Trim(); }
            set { inputTextBox.Text = value; }
        }

        /// <summary>
        /// 是否必填
        /// </summary>
        private bool Required { get; set; }

        /// <summary>
        /// 显示输入框
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">信息</param>
        /// <param name="inputText">录入文本</param>
        /// <param name="required">是否必填</param>
        /// <returns>对话框返回值</returns>
        public DialogResult ShowPromptDialog(string title, string message, string inputText, bool required)
        {
            Text = title;
            captionControl1.CaptionText = message;
            inputTextBox.Text = inputText;
            Required = required;
            ShowInTaskbar = false;
            StartPosition = FormStartPosition.CenterParent;
            return ShowDialog();
        }

        /// <summary>
        /// 显示输入框
        /// </summary>
        /// <param name="message">信息</param>
        /// <param name="inputText">录入文本</param>
        /// <param name="required">是否必填</param>
        /// <returns>对话框返回值</returns>
        public DialogResult ShowPromptDialog(string message, string inputText, bool required)
        {
            return ShowPromptDialog(message, message, inputText, required);
        }

        /// <summary>
        /// 显示输入框
        /// </summary>
        /// <param name="message">信息</param>
        /// <param name="inputText">录入文本</param>
        /// <returns>对话框返回值</returns>
        public DialogResult ShowPromptDialog(string message, string inputText)
        {
            return ShowPromptDialog(message, message, inputText, true);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Required && string.IsNullOrEmpty(inputTextBox.Text))
            {
                MessageBoxHelper.ShowWarn(captionControl1.CaptionText);
                inputTextBox.Select();
                return;
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void PromptForm_Load(object sender, EventArgs e)
        {
            inputTextBox.SelectAll();
        }
    }
}